using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;

namespace SMSManager.Data
{
	public static class NotifyPropertyChangedBaseExtension
	{
		public static void OnPropertyChanged<T, TProperty>(this T viewModelBase,
		                                                   Expression<Func<T, TProperty>> propertyExpression)
			where T : NotifyPropertyChangedBase
		{
			var memberExpression = propertyExpression.Body as MemberExpression;
			if (memberExpression == null || (memberExpression != null &&
			                                 memberExpression.Member.MemberType != MemberTypes.Property))
			{
				throw new ArgumentException(
					"The specified expression does not represent a valid property");
			}
			viewModelBase.OnPropertyChanged(new PropertyChangedEventArgs(memberExpression.Member.Name));
		}
	}
}